package com.lzy.mall.product.controller;


import com.lzy.mall.common.utils.PageUtils;
import com.lzy.mall.common.utils.ResultUtils;
import com.lzy.mall.product.entity.PmsSpuInfo;
import com.lzy.mall.product.service.PmsSpuInfoService;
import com.lzy.mall.product.vo.SpuSaveVo;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * spu信息(PmsSpuInfo)表控制层
 *
 * @author lzy
 * @since 2021-08-25 11:41:25
 */
@RestController
@RequestMapping("spuinfo")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class PmsSpuInfoController {
    private final PmsSpuInfoService spuInfoService;

    //商品上架
    @PostMapping("/{spuId}/up")
    public ResultUtils spuUp(@PathVariable("spuId") Long spuId){
        spuInfoService.spuUp(spuId);
        return ResultUtils.ok();
    }

    @PostMapping("/save")
    public ResultUtils save(@RequestBody SpuSaveVo saveVo){
        spuInfoService.saveSpuInfo(saveVo);
        return ResultUtils.ok();
    }

    @GetMapping("/list")
    public ResultUtils list(@RequestParam Map<String, Object> params){
        PageUtils page = spuInfoService.queryPageByCondition(params);

        return ResultUtils.ok().put("page", page);
    }

    @GetMapping("/skuId/{id}")
    public ResultUtils getSkuInfoBySkuId(@PathVariable("id") Long skuId){
        PmsSpuInfo info = spuInfoService.getSkuInfoBySkuId(skuId);
        return ResultUtils.ok().setData(info);
    }

}
